package 分类.链表;

import java.util.List;

public class 反转链表II {
    public ListNode reverseBetween(ListNode head, int left, int right) {
         // base case
          if(left==1) {
              return reverse(head, right);
          }else {
              head.next=reverseBetween(head.next,left-1,right-1);
              return head;
          }
    }
    ListNode succ=null;
    ListNode reverse(ListNode head,int n){
        if(n==1){
            succ=head.next;
            return head;
        }

            ListNode last=reverse(head.next,n-1);
            head.next.next=head;
            head.next=succ;

            return head;
    }



}
